/*****************************************************************************
Copyright 2006 Kervin L. Pierre
    EMAIL: otlkcon@adevsoft.com

This file is part of Otlkcon.

Otlkcon is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

Otlkcon is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Lesser GNU General Public License for more details.

You should have received a copy of the Lesser GNU General Public License
along with Otlkcon; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*******************************************************************************/

#pragma once
#include "StdAfx.h"
#include "O_IProp.h"
#include "O_ITable.h"
#include "O_IAttach.h"

#include <vector>

using namespace std;

class O_IAttach;
class O_IFolder;

class O_IMessage : public O_IProp
{
public:
   // MAPI_IUNKNOWN_METHODS(IMPL);
    MAPI_IMESSAGE_METHODS(IMPL);

    // Misc. overloaded functions
    ULONG STDMETHODCALLTYPE Release(void);
    STDMETHODIMP SaveChanges( ULONG ulFlags );
    STDMETHODIMP GetProps(LPSPropTagArray lpPropTagArray,
                      ULONG        ulFlags,
                      ULONG        *lpcValues,
                      LPSPropValue *lppPropArray );
	
    O_IMessage();
    ~O_IMessage();

    void Destroy();
    HRESULT Create( otlkcon_generic_msgstore *mstr, O_ENTRYID *par, ULONG mflags, MAPIUID ig );
    HRESULT Load( otlkcon_generic_msgstore *mstr, O_ENTRYID *eid );
    HRESULT Load( otlkcon_generic_msgstore *mstr, char *tableID );

    bool hasAttach;

    O_ITable *attachmentTable;
    O_ITable *recipientTable;

	//Recipients support
	//We will store recipients in memory
	//and modify them in SaveChanges
	LPTABLEDATA	m_lpRecipientsSnapShot;
    LPTABLEDATA	m_lpAttachmentsSnapShot;

	BOOL		m_bRecipientsModified;
    BOOL		m_bAttachmentsModified;

	//used to create unique row id for a new recipients
	DWORD		m_dwRecipRowID;

	STDMETHODIMP CheckRecipients(ULONG ulFlags, LPADRLIST lpRecipients);
	STDMETHODIMP ClearRecipients();
	STDMETHODIMP AddRecipients(LPSRowSet lpRecipients);
	STDMETHODIMP ModifyOrDeleteRecipients(ULONG ulFlags, LPSRowSet lpRecipients);
	STDMETHODIMP CalculateDisplayProperties();
	STDMETHODIMP SaveRecipients();
	STDMETHODIMP GetColumns(LPSRow lpRow, LPSPropTagArray *lppColumns);

    HRESULT GetEidFromTableName( char *tbl, O_ENTRYID **eid, const MAPIUID *sg);

    STDMETHODIMP SaveAttachments();

    STDMETHODIMP ICalExport( icalcomponent **iCal );
    STDMETHODIMP ICalImport( icalcomponent *iCal );

    STDMETHODIMP ICalExport( wchar_t **iCal );
    STDMETHODIMP ICalImport( wchar_t *iCal );

	//TODO: These functions should not be transacted
	HRESULT      BeginUploading();
	HRESULT      CompleteUploading();
	
	BOOL		 IsUploading();
	BOOL		 IsDownloading();
	
	HRESULT      BeginDownloading();
	HRESULT      CompleteDownloading();
	
	BOOL		 HasForeignID();
	HRESULT      CreateNewForeignID();
	//END TODO: These functions should not be transacted

	//BEGIN: for testing using undocumented Outlook's MIMDIR converter
	STDMETHODIMP PreICalImportMIMEDIR( string *iCal );
	STDMETHODIMP ICalImportMIMEDIR( wchar_t *iCal , O_IFolder* lpParentFolder);
	STDMETHODIMP PostICalImportMIMEDIR( wchar_t *iCal );
	
	STDMETHODIMP ICalExportMIMEDIR( wchar_t **iCal );
	STDMETHODIMP PostICalExportMIMEDIR( wchar_t **iCal );
	//END: for testing using undocumented Outlook's MIMDIR converter
	
	HRESULT SynchronizeBody();
	HRESULT IsPropertyChanged(ULONG ulPropTag, LPBOOL lpbChanged);
    vector<O_IAttach *> unsavedAttachments;
    vector<O_ENTRYID *> deletedAttachments;
};
